# ！ /usr/bin/python3
# -*- coding:utf-8 -*-
# @Author:Peng Cao
# @File: 03img_thresh.py
# @Software: PyCharm
import cv2.cv2 as cv
import matplotlib.pyplot as plt
import numpy as np


def img_info():
    """
    查看图片转化成数据
    :return:
    """
    img = cv.imread('./data/lena.jpg')
    new_img = img[0:3, 0:3]
    print(new_img)
    cv.imshow("new_img", new_img)
    cv.waitKey(0)
    cv.destroyAllWindows()


def so_img():
    """
    梯度处理,求边界值
    :return:
    """
    img = cv.imread('./data/pie.png')
    new_img_x = cv.Sobel(img, cv.CV_64F, 1, 0, ksize=3)
    new_img_x = cv.convertScaleAbs(new_img_x)  # 将上步中的new_img中的负数转化为正数
    new_img_y = cv.Sobel(img, cv.CV_64F, 0, 1, ksize=3)
    new_img_y = cv.convertScaleAbs(new_img_y)  # 将上步中的new_img中的负数转化为正数
    new_img = cv.addWeighted(new_img_x, 0.5, new_img_y, 0.5, 0)
    res, new_img = cv.threshold(new_img, 127, 255, cv.THRESH_BINARY)
    new_img = np.hstack((img, new_img_x, new_img_y, new_img))
    cv.imshow('res', new_img)
    cv.waitKey(0)
    cv.destroyAllWindows()


if __name__ == '__main__':
    # img_info()
    so_img()
